Methods | |
---|---|
get() | The get method returns the current value of the variable. |
Srt(value) | The set method updates the variable. |
from tkinter import * class MyWin(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.a=StringVar() self.b=StringVar() self.t1=Entry(self,textvariable=self.a) self.t1.pack() self.btn=Button(self,text="Exchange",command=self.exg) self.btn.pack() self.t2=Entry(self,textvariable=self.b) self.t2.pack() def exg(self): s1=self.a.get() s2=self.b.get() self.a.set(s2) self.b.set(s1) win=MyWin() win.mainloop()
from tkinter import * class MyWin(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.a=IntVar() self.t1=Entry(self,textvariable=self.a) self.t1.pack() self.btn=Button(self,text="Increment",command=self.incr) self.btn.pack() def incr(self): n=self.a.get() n=n+1 self.a.set(n) win=MyWin() win.mainloop()
from tkinter import * from tkinter.messagebox import * class MyWin(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.a=IntVar() self.t1=Entry(self,textvariable=self.a,width=3) self.t1.pack() self.btn=Button(self,text="Factorial",command=self.calfact) self.btn.pack() def calfact(self): n=self.a.get() f=1 for i in range(1,n+1): f=f*i showinfo(message="Factorial of "+str(n)+" is "+str(f)) win=MyWin() win.mainloop()